﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using RecipeManager.Layout;
using System.Diagnostics;

namespace RecipeManager
{
    public partial class ReportForm : Form
    {

        public ReportForm()
        {
            InitializeComponent();
        }

        public ReportForm(Recipe recipe)
            : this()
        {
            string path = Path.GetFullPath(recipe.HTMLReportPath);
            browserMain.Navigate(path);
            _txtAddress.Text = path;
        }

        public ReportForm(List<Recipe> list)
            : this()
        {
            string path = Path.GetFullPath(Recipe.RepositoryPath + Recipe.GenerateFileNameByString("_general") + Recipe.DefaultReportFileName);
            string dir = Path.GetFullPath(Recipe.RepositoryPath + Recipe.GenerateFileNameByString("_general"));

            string content = LayoutGeneratorHTML1.GenerateHTMLBegin("Rezepte");
            string pagebreak = "";
            list.ForEach(x =>
                {
                    content += "<div style=\"" + pagebreak + "\">" + LayoutGeneratorHTML1.GenerateHTMLBody(x) + "</div>";
                    pagebreak = "page-break-before:always";
                });
            content += LayoutGeneratorHTML1.GenerateHTMLEnd();

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            File.WriteAllText(path, content);

            browserMain.Navigate(path);
            _txtAddress.Text = path;
        }

        private void _butGO_Click(object sender, EventArgs e)
        {
            Process.Start(_txtAddress.Text);
            this.Close();
        }
    }
}
